Feature: Index Churches
  In order to create, edit, update or delete church information
  As a user
  I want to be able see all churches and search for churches
  
  Background:
    Given the following church records
      | name        | address  | created_at |
      | church a    | a        | 2001-01-01 |
      | church b    | b        | 2001-01-01 |
      | church c    | c        | 2001-01-01 |
      | church d    | d        | 2001-01-01 |
      | church e    | e        | 2001-01-01 |
      | church f    | f        | 2001-01-01 |
      | church g    | g        | 2001-01-01 |
      | church h    | h        | 2001-01-01 |
      | church i    | i        | 2001-01-01 |
      | church j    | j        | 2001-01-01 |
      | church k    | k        | 2001-01-01 |
      | church l    | l        | 2001-01-01 |
      | church m    | m        | 2001-01-01 |
      | church n    | n        | 2001-01-01 |
      | church o    | o        | 2001-01-01 |
      | church p    | p        | 2001-01-01 |
      | church q    | q        | 2001-01-01 |
      | church r    | r        | 2001-01-01 |
      | church s    | s        | 2001-01-01 |
      | church t    | t        | 2001-01-01 |
      | church u    | u        | 2001-01-01 |
      | church v    | v        | 2001-01-01 |
      | church w    | w        | 2001-01-01 |
      | church x    | x        | 2001-01-01 |
      | church y    | y        | 2001-01-01 |
      | church z    | z        | 2001-01-01 |
    And I am on the homepage
    When I follow "Admin"
    When I follow "Churches"

  Scenario: Listing of churches
    Then I should see "church a"
    Then I should see "church b"
    Then I should see "church c"
    Then I should see "church d"
    Then I should see "church e"
    Then I should see "church f"
    Then I should see "church g"
    Then I should see "church h"
    Then I should see "church i"
    Then I should see "church j"
    Then I should see "1"
    Then I should see "2"
    Then I should see "3"
    Then I should see "Next"
    Then I should see "Last"
    
  Scenario: Listing of churches page 2
    When I follow "2"
    Then I should see "church k"
    Then I should see "church l"
    Then I should see "church m"
    Then I should see "church n"
    Then I should see "church o"
    Then I should see "church p"
    Then I should see "church q"
    Then I should see "church r"
    Then I should see "church s"
    Then I should see "church t"
    Then I should see "1"
    Then I should see "2"
    Then I should see "3"
    Then I should see "First"
    Then I should see "Prev"
    Then I should see "Next"
    Then I should see "Last"

  Scenario: Listing of churches page 3
    When I follow "3"
    Then I should see "church u"
    Then I should see "church v"
    Then I should see "church w"
    Then I should see "church x"
    Then I should see "church y"
    Then I should see "church z"
    Then I should see "1"
    Then I should see "2"
    Then I should see "3"
    Then I should see "First"
    Then I should see "Prev"
    
  Scenario: Sorting of churches by name
    When I follow "Name"
    Then I should see "church z"
    Then I should see "church y"
    Then I should see "church x"
    Then I should see "church w"
    Then I should see "church v"
    Then I should see "church u"
    Then I should see "church t"
    Then I should see "church s"
    Then I should see "church r"
    Then I should see "church q"
    Then I should see "1"
    Then I should see "2"
    Then I should see "3"
    Then I should see "Next"
    Then I should see "Last"

  Scenario: Search for a church
    And I fill in "search" with "church k"
    And I press "Search"
    Then I should see "church k"

  Scenario: Recent filter
    Given the following church records
      | name        | address  | created_at |
      | znew        | new      |            |
    When I follow "Recent"
    Then I should see "znew"
    Then I should not see "church a"
    Then I should not see "Next"
    Then I should not see "Prev"
